package cn.itsource.basic.listener;

import cn.itsource.system.service.IPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
@Slf4j
public class PermissionAddListener implements ServletContextListener {

    @Autowired
    private IPermissionService permissionService;

    /**
     * spring容器初始化
     * @param sce
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        log.info("项目启动的时候我这里可用干点事!!!!");
        //扫描自定义注解往数据添加接口相关权限数据
        new Thread(() -> {
            permissionService.scan();
        }).start();
    }

    /**
     * spring容器销毁
     * @param sce
     */
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        log.info("销毁了!!!!!!");
    }
}
